/**
 * @defgroup pkp_form
 */

/**
 * @file styles/form.less
 *
 * Copyright (c) 2014-2018 Simon Fraser University
 * Copyright (c) 2003-2018 John Willinsky
 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
 *
 * @ingroup pkp_form
 *
 * @brief Form Builder Vocabulary classes
 */

/**
 * FBV styles
 */
.pkp_form {
	font-size: @font-sml;
	line-height: @line-sml;

	fieldset {
		margin: 0 0 @double 0;
		padding: 0;
		border: none;
		// Chrome sets the fieldset min-width to min-content, which
		// prevents our grids from shrinking properly.
		// See: https://css-tricks.com/almanac/properties/w/width/#article-header-id-2
		min-width: auto;

		&:last-child {
			margin-bottom: 0;
		}
	}

	// At the moment we don't really differentiate in the way we use these
	// elements
	legend,
	label,
	.section > .label // Prevents it from effecting .label elements in grids
	{
		display: block;
		font-size: @base;
		font-weight: @bold;
	}

	// error
	label.error, span.error {
		margin-top: 4px;
		margin-bottom: 4px;
		padding-left: 0.5em;
		border-left: @half solid @no;
		font-size: @font-sml;
		line-height: @line-sml;
		color: @no;
	}

	.section {
		margin-bottom: @double;

		&:last-child {
			margin-bottom: 0;
		}

		&:not(.inline) {
			.pkp_helpers_clear();
		}
	}

	// Inline sections
	.inline {
		float: left;
		padding-right: @base;

		&:last-child {
			padding-right: 0;
		}
	}

	label {
		cursor: pointer;
	}

	input[type="date"],
	input[type="email"],
	input[type="file"],
	input[type="month"],
	input[type="number"],
	input[type="password"],
	input[type="search"],
	input[type="tel"],
	input[type="text"],
	input[type="url"],
	input[type="week"],
	textarea,
	select {
		display: block;
		width: 100%;
		height: @double; // browser-compatibility for select fields
		background-color: @lift;
		padding: 0 0.25em;
		font-size: @font-sml;
		line-height: @double;
		border: @bg-border;
	}

	textarea {
		height: 10em;
		line-height: @line-sml;
	}

	// Textarea size modifiers
	.short {
		height: 6em;
	}

	.medium {
		height: 12em;
	}

	.tall {
		height: 18em;
	}

	// Checkbox and radio lists
	.checkbox_and_radiobutton {
		margin: 0;
		padding: 0;
		list-style: none;

		input {
			display: inline-block;
			margin-right: 0.5em;
		}

		li label {
			font-size: @font-sml;
			font-weight: @normal;
		}
	}

	// Required feilds
	.req {
		font-weight: @bold;
		color: @no;
		padding-left: 0.25em;
	}

	// Disabled fields
	input[disabled],
	textarea[disabled],
	select[disabled] {
		background: @bg;
		color: @text-light;
		color: @text-light-rgba;
	}

	// Field descriptions and labels beneath fields
	.description,
	.sub_label {
		font-size: @font-sml;
		line-height: @line-sml;
		font-weight: @normal;
		color: @text-light;
		color: @text-light-rgba;
	}

	.description {
		margin-bottom: @half;
	}

	.sub_label {
		font-style: italic;
	}

	// When a .description element is followed by another .description
	.description + .description,
	// When a .description element is attached to a fieldset and followed
	// by a section
	.description + .section {
		margin-top: @double;
	}

	// Form controls that toggle between display and editing states
	[data-pkp-editable] {

		[data-pkp-editable-view="input"],
		[data-pkp-editable-view="input"] label:not(.error),
		&.isEditing [data-pkp-editable-view="display"] {
			position: absolute;
			top: -9999px;
			left: -9999px;
		}

		[data-pkp-editable-view="display"],
		&.isEditing [data-pkp-editable-view="input"] {
			position: relative;
			top: auto;
			left: auto;
		}

		.edit {
			font-size: @font-sml;
			margin-left: 1em;
			text-decoration: none;

			&:before {
				.fa();
				content: @fa-var-pencil;
				margin-right: 0.25em;
			}
		}
	}

	// Localization popovers
	.localization_popover_container {
		position: relative;
		// fix collapsed div in firefox, which caused the translation icon to
		// appear in the wrong space
		display: block;

		// Localization globe icon within TinyMce
		&:after {
			.fa();
			content: @fa-var-globe;
			position: absolute;
			top: @half - 2;
			right: @base;
			z-index: 2;
			width: 20px;
			height: 20px;
			font-size: 20px;
			text-align: center;
			color: @text-light;
		}
	}

	.localization_popover_container_focus,
	.localization_popover_container_focus_forced {
		display: block;
		padding: @half;
		background-color: @bg;

		&:after {
			top: @base - 2;
			color: @text;
		}
	}

	.localizationIncomplete:after {
		color: @warn;
	}

	.localizationComplete:after {
		color: @yes;
	}

	.localization_popover {
		display: none;
		position: absolute;
		left: 0;
		z-index: 99;
		padding: @half;
		background-color: @bg;
	}

	.localization_popover_container_focus_forced .localization_popover {
		display: block;
		position: relative;
		margin-top: @half;
		padding: 0;
	}

	// Position locale label off-screen but accessible to screen readers
	label.locale {
		&:extend(.pkp_screen_reader);

		&:focus {
			&:extend(.pkp_screen_reader:focus);
		}
	}

	label.locale_textarea {
		margin-top: @base;
		font-size: @font-sml;
	}

	// Loading indicator
	.pkp_spinner {
		opacity: 0;
		float: right;
		margin-right: 0.5em;
		.transition(opacity 0.3s ease-in-out);

		&.is_visible {
			opacity: 1;
		}
	}

	// Hide form elements when in wizard mode
	.is_wizard_mode {
		display: none;
	}

	// Star selection in radio buttons
	.pkp_star_selection {
		font-size: @font-sml;
		font-weight: @normal;

		.fa {
			color: @star-on;
		}
	}
}

// Row of buttons
.form_buttons {

	a {
		&:extend(.pkp_button_link all);

		&.cancelButton {
			&:extend(.pkp_button_link_offset all);
		}
	}
}

a[id^="publicIdentifiersForm-clearPubId-button"],
a[id^="publicIdentifiersForm-clearObjectsPubIds-button"] {
	&:extend(.pkp_button all);
	&:extend(.pkp_button_offset all);
}

// Required fields notice
.formRequired {
	display: inline-block;
	margin-top: @double;
	padding: 12px 1em;
	background: @bg-light;
	border-left: 2px solid @primary;
	font-size: @font-sml;
	font-style: italic;
	line-height: @line-sml;
}

// Form file view
.pkp_form_file_view {
	.pkp_helpers_clear;
	margin-bottom: @base;
	padding: @double;
	background: @bg-light;

	.data {

		span {
			display: block;
			font-size: @font-sml;
			line-height: @line-sml;
		}

		.title {
			font-weight: @bold;
		}

		.value {
			margin-bottom: @base;
			color: @text-light;
			color: @text-light-rgba;

			&:last-child {
				margin-bottom: 0;
			}
		}
	}

	input {
		color: @text;
		color: @text-rgba;
	}
}

// To be used alongside .pkp_form_file_view (both classes assigned)
.pkp_form_image_view {

	.img {
		text-align: center;

		img {
			max-width: 100%;
		}
	}

	// @todo use common breakpoints
	@media(min-width: 767px) {

		> div {
			width: 50%;
			float: right;
		}

		.data {
			float: left;
			padding-right: @double;
		}
	}
}

// Link action links that should have a warning color
[class*=pkp_linkaction_deleteFile] {
	color: @no;
}

// jQuery UI datepicker
.ui-datepicker {
	width: 25em;
	padding: @base;
	max-width: 100%;
	background: @bg;
	box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.ui-datepicker-prev,
.ui-datepicker-next {
	display: block;
	position: absolute;
	top: @base;
	left: @base;
	width: @double;
	height: @double;
	text-align: center;
	cursor: pointer;

	&:before {
		.fa();
		content: @fa-var-arrow-left;
	}


	> span {
		&:extend(.pkp_screen_reader);
	}
}

.ui-datepicker-next {
	left: auto;
	right: @base;

	&:before {
		content: @fa-var-arrow-right;
	}
}

.ui-datepicker-title {
	margin-bottom: @base;
	font-size: @font-sml;
	font-weight: @bold;
	text-align: center;
}

.ui-datepicker-calendar {
	width: 100%;
	text-align: center;

	thead {
		font-size: @font-sml;
	}

	tbody {
		background: @lift;

		tr {
			border-top: 1px solid @bg;

			&:first-child {
				border-top: none;
			}
		}
	}

	a {
		display: block;
		text-decoration: none;

		&:hover,
		&:focus {
			background: @primary;
			color: #fff;
		}
	}
}

// Autocomplete fields
// @todo the UI could probably be improved. When several results appear, you
//  can loop through them with up and down keys, but that's not really intuitive
//  with the UI pattern that's been implemented. Also, the suggestions panel
//  could be absolutely positioned. Right now it causes a lot of jankiness when
//  it comes in and out.
.pkp_form input.ui-autocomplete-input {
	display: inline-block; // Allow the label to sit on top
}

.ui-autocomplete {
	&:extend(.pkp_unstyled_list);
	width: 100%;
	max-width: 40em;
	border: @bg-border;
	border-top: none;
	background: @lift;
	font-size: @font-tiny;
	line-height: @line-tiny;
	box-shadow: 2px 2px 4px rgba(0,0,0,0.3);
	z-index: 99999;

	> li {
		display: block;
		padding: @half;
		cursor: pointer;
		text-overflow: ellipsis;
		overflow-x: hidden;
		white-space: nowrap;
		cursor: pointer;

		&.ui-state-focus {
			background: @bg;
		}
	}
}

.ui-autocomplete-loading {
	background-image: url();
	background-position: center right;
	background-size: @base;
	background-repeat: no-repeat;
}

// Tag-it component
.tagit {
	&:extend(.pkp_unstyled_list);
	&:extend(.pkp_form input[type="text"]);
	.pkp_helpers_clear();
	height: auto; // overwrite text field styles
	cursor: text;
	min-height: 2.5em;

	> li {
		display: inline-block;

		&.tagit-choice {
			margin-right: 0.5em;
			padding-left: 0.5em;
			background: @bg;
			border-radius: @radius;
			line-height: @double - @half;
		}
	}

	input[type="text"] {
		display: inline-block;
		border: none;
		width: inherit;
		line-height: 30px;
		height: 30px;
		vertical-align: top;
		padding: 0 0.5em;
	}

	.tagit-new input:focus {
		outline: 0;
	}
}

.tagit-close {
	padding: 0 0.5em;
	color: @no;
	cursor: pointer;
}

// Fixes the positioning of tinymce tooltips
// skin.min.css (the tinymce we're loading) sets their position to absolute,
// but the tooltips seem to set position relative to the viewport, not the
// document. This causes problems for textareas in modals, where the scroll
// position of the modal differs from the scroll position of the document.
// "I'm almost definitely pretty sure that might be the explanation." ~NW
.mce-widget.mce-tooltip {
	position: fixed;
}

// Forms in modals
.pkp_modal .pkp_form {

	.form_buttons {
		&:extend(.pkp_modal_panel > .footer all);
		margin: @base -@base -@base;
	}

	// Override grid filter form buttons which appear in modals
	.pkp_form.filter .form_buttons {
		margin: 0;
		padding: 0;
		background: none;
	}
}

// Navigation Menu drag-and-drop
.pkp_nav_management {
	.pkp_helpers_clear;
	position: relative;
	border: @bg-border;
}

.pkp_nav_assigned,
.pkp_nav_unassigned {
	float: left;
	width: 50%;

	ul {
		.pkp_unstyled_list;

		ul {
			margin-left: @double;
		}
	}

	> ul {
		padding-bottom: @double * 2;
	}
}

.pkp_nav_management .item {
	position: relative;
	margin: @base;
	border: @bg-border;
	padding: @half @base;
	cursor: pointer;

	.item_title {
		padding-left: @base * 2;

		.fa {
			position: absolute;
			top: 0;
			left: 0;
			width: @double;
			height: 100%;
			border-right: @bg-border;
			line-height: @double + @half;
			text-align: center;
		}
	}

	.item_buttons {
		position: absolute;
		top: 0;
		right: 0;
		height: 100%;
		line-height: @double + @half;

		button {
			margin-right: 0.5em;
			padding: 0 0.5em;
			border: none;
			background: transparent;
			line-height: @double + @half;
			color: @primary;
			cursor: pointer;
		}
	}
}

.pkp_nav_item_placeholder,
.pkp_nav_assigned .pkp_is_sorting .ui-sortable:empty {
	margin: @base;
	border: 1px dashed @bg-border-color-light;
	padding: @half @base @half (@base * 3);
	min-height: @double + @half;
}

.pkp_nav_item_placeholder {
	border-color: @bg-border-color;
}

.pkp_nav_assigned .pkp_is_sorting .ui-sortable:empty {
	margin-left: @double + @base;
	margin-right: @base;
}

// Hide slots nested two levels deep
.pkp_nav_assigned .pkp_is_sorting ul .ui-sortable {
	display: none;
}

.pkp_nav_assigned {

	&:before {
		content: '';
		position: absolute;
		top: 0;
		left: 50%;
		height: 100%;
		border-right: @bg-border;
	}
}

.pkp_nav_management_header {
	padding: @half @base;
	border-bottom: @bg-border;
	font-weight: @bold;
}

.pkp_nav_unassigned {

	.item {
		color: @text-light;
		border-color: @bg-border-color-light;

		.item_title {

			.fa {
				border-right-color: @bg-border-color-light;
			}
		}

		.item_buttons .fa {
			color: @text-light;
		}
	}
}

// Override form styles that are effecting reviewer selection grid filters
.pkp_form {

	.pkpListPanel__filterInputLabel {
		font-size: @font-sml;
		font-weight: @normal;
	}
}

.pkp_form {

	// @todo all below
	span.pkp_form_success {
		color: #090;
		font-weight: bold;
		font-size: 100%;
	}

	.pkp_form_file_input_container {
		height: 30px;
		width: 350px;
		position:relative;
		float:left;

		.pkp_form_fakeFile {
			left:0;
			line-height:90%;
			margin:0;
			padding:0;
			position:absolute;
			top:0;
			width:350px;
			z-index:1;
		}

		.pkp_form_fakeInput {
			margin-bottom:5px;
			margin-left:0;
			height:15px;
			padding-left:3px;
			padding-top:1px;
			width:241px;
		}

		.pkp_form_fakeButton {
			line-height:90%;
		}

		.pkp_form_uploadFile {
			line-height: 90%;
			height: 29px;
		}
	}

	input.pkp_form_upload_field {
		padding: 3px;
		margin: 0;
		height: 30px;
		width: 350px;
		position: relative;
		z-index: 2;
		text-align:right;
		-moz-opacity:0;
		filter:alpha(opacity=0);
		opacity: 0;
	}

	.pkp_form_hidden {
		display:none !important;
	}
}
